﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import reprise.commands.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;

    public class PlayRandomEffectsCommand extends Command {

        private var _randomSounds:Array;
        private var _delayBetweenSoundsCommand:TimerCommand;

        public function PlayRandomEffectsCommand(){
            this._randomSounds = [GameConstants.SOUND_BACKGROUND_MACHINE_2, GameConstants.SOUND_BACKGROUND_TELEPHONE_2];
            super();
        }
        override public function execute():void{
            this.startRandomBackgroundSounds();
        }
        private function startRandomBackgroundSounds():void{
            this._delayBetweenSoundsCommand = null;
            this._delayBetweenSoundsCommand = new TimerCommand(Numbers.randomIntBetween(30000, 60000));
            this._delayBetweenSoundsCommand.addEventListener(Event.COMPLETE, this._delayBetweenSoundsCommand_complete);
            this._delayBetweenSoundsCommand.execute();
        }
        private function _delayBetweenSoundsCommand_complete(_arg1:Event):void{
            this.startRandomBackgroundSounds();
            this.playRandomSound();
        }
        private function playRandomSound():void{
            var _local1:int = Numbers.randomIntBetween(0, (this._randomSounds.length - 1));
            var _local2:String = this._randomSounds[_local1];
            var _local3:Object = new Object();
            _local3[EventConstants.SOUND_VOLUME] = 0;
            _local3[EventConstants.SOUND_DELAY] = 0;
            dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, _local2));
        }

    }
}//package net.wooga.pets.controllers 
